package com.xca.is.repository;

import com.xca.is.entity.TrainEntity;
import com.xca.is.service.TrainService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class TrainRepository {
    private static final String URL = "https://api.yujn.cn/api/" ;
    private TrainService service ;

    public TrainRepository(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl(URL)
                        .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                        .addConverterFactory(GsonConverterFactory.create())
                        .build() ;
                service = retrofit.create(TrainService.class) ;
            }
        }).start();

    }
    public Observable<TrainEntity> getData(String go, String to, String time){
        return service.gatData("json" , go , to , time)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io()) ;
    }
}
